package com.gxa.uhome.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.gxa.uhome.mapper.LogMapper;
import com.gxa.uhome.pojo.Admin;
import com.gxa.uhome.pojo.Log;
import com.gxa.uhome.service.LogService;
import com.gxa.uhome.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

/**
 * @author: qingyao
 * @date: 12:45 2021/6/5
 */
@RestController
@RequestMapping("/log")
@Api(value = "操作记录模块",produces = "application/json;charset=UTF-8",tags = "Log操作记录模块")
public class LogController {
    @Resource
    LogService logService=null;
/*    @ApiOperation(value = "根据操作员id搜索操作员用户名的操作",
            notes = "请查看",//response = Map.class,
            httpMethod = "post")
    @PostMapping("/selectbyadmin")
    @ApiImplicitParam(name="id",value = "adminid操作员id")
    @ResponseBody
    //@ResponseBody的作用其实是将java对象转为json格式的数据。
    public JsonResult selectbyid(@RequestParam Integer id) throws Exception{
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setMsg("查询成功");
        jsonResult.setData("查了");
        return jsonResult;
    }*/

    @ApiOperation(value = "查看所有操作记录的操作",
    notes = "请查看",//response = Log.class,
    httpMethod = "POST")
    @PostMapping("/getall")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页数"),
            @ApiImplicitParam(name = "size", value = "大小长度")
    })
    @ResponseBody
    public JsonResult get(@RequestParam Integer page,@RequestParam Integer size) throws Exception{
        JsonResult jsonResult=new JsonResult();
        List<Log> selectall = logService.selectall((page - 1) * size, size);
        if(selectall!=null){
            jsonResult.setCode("1");
            jsonResult.setMsg("查询成功");
            jsonResult.setData(selectall);
        }else{
            jsonResult.setCode("0");
            jsonResult.setMsg("查询失败");
        }
        return jsonResult;
    }

    @ApiOperation(value = "根据操作人或加上操作时间段或加上操作类型搜索的操作",
            notes = "请查看",//response = Log.class,
            httpMethod = "POST")
    @PostMapping("/select")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "操作人姓名"),
            @ApiImplicitParam(name = "star", value = "起始时间"),
            @ApiImplicitParam(name = "end", value = "结束时间"),
            @ApiImplicitParam(name = "type", value = "操作类型"),
            @ApiImplicitParam(name = "page", value = "页数"),
            @ApiImplicitParam(name = "size", value = "大小长度")
    })
//    @ResponseBody
    public JsonResult slctbyname(@RequestParam(required = false) String name, @RequestParam(required = false) String star,
                                 @RequestParam(required = false) String end, @RequestParam(required = false) String type,
                                 @RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
                                 @RequestParam(value = "size", defaultValue = "5", required = false) Integer size) throws Exception{
        JsonResult jsonResult=new JsonResult();
        List<Log> select = logService.select(name, star, end, type,(page-1)*size,size);
        if(select!=null){
            jsonResult.setCode("1");
            jsonResult.setMsg("查询成功");
            jsonResult.setData(select);
        }else{
            jsonResult.setCode("0");
            jsonResult.setMsg("查询失败");
        }
        return jsonResult;
    }



/*    @ApiOperation(value = "导出Excel的操作",
            notes = "导出字段为该表格中的字段",//response = Log.class,
            httpMethod = "post")
    @PostMapping("/export")
    @ResponseBody
    public JsonResult export() throws Exception{
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setMsg("查询成功");
        jsonResult.setData("查了");
        return jsonResult;
    }*/
}
